package com.poker.service;

import com.poker.entity.UserHonor;
import com.poker.repository.UserHonorRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName UserHonorService
 * @Description TODO
 * @Author duyuanyuan
 * @Date 2019/3/13 13:35
 * @Version 1.0
 **/
@Service
public class UserHonorService {

    @Resource
    private UserHonorRepository userHonorRepository;

    public UserHonor getByUseridAndActivityId(String userid, String activityid) {
       UserHonor honor = userHonorRepository.findByUserAndActivityId(userid,activityid);
       if(honor==null){
           UserHonor userHonor=new UserHonor();
           userHonor.setActivityId(activityid);
           userHonor.setUserId(userid);
           userHonor.setHonorDate(new Date());
           UserHonor userhonor1 = userHonorRepository.saveAndFlush(userHonor);
           return userhonor1;
       }
        return honor;
    }

    public void update(UserHonor userHonor) {
        UserHonor one = userHonorRepository.getOne(userHonor.getId());
        userHonor.setHonorDate(one.getHonorDate());
        userHonorRepository.saveAndFlush(userHonor);
    }
}
